package com.freesun.autoui.product.healthcenter.share;

import com.freesun.autoui.product.healthcenter.pageaction.LogOutPageAction;
import com.freesun.autoui.product.healthcenter.pageaction.LoginPageAction;
import com.freesun.autoui.share.OperateCookies;
import com.freesun.autoui.share.SetupBrowser;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

/**
 * desc:loginpagecase
 * Created by yangfei on 13-12-31.
 */
public class LoginPageCase {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    WebDriver driver;

    @Parameters({"remoteIp","browser"})
    @BeforeTest
    public void init(String remoteIp,String browser){
        driver= SetupBrowser.initBrower(remoteIp,browser);
        //OperateCookies.deleteAllCookies(driver);
    }

    /**
     * @desc 用户登录
     * @param url
     * @param username
     * @param password
     * @param intoUrl
     * @param logOutText
     * @param context
     */
    @Parameters({"url", "username", "password","intoUrl","logOutText"})
    @Test
    public void loginIn(String url, String username,String password,String intoUrl,String logOutText, ITestContext context){

        LoginPageAction.loginIn(driver,url, username, password);

        String text= LoginPageAction.checkText(driver,intoUrl);

        if (logOutText.equalsIgnoreCase(text)) {
            Assert.assertTrue(true);
        }else {
            Assert.assertTrue(false);
        }
    }


    /**
     * @des 退出登录
     * @param intoUrl
     * @param loginInText
     */
    @Parameters({"intoUrl","loginInText"})
    @Test
    public void logOut(String intoUrl,Boolean loginInText){
        LogOutPageAction.logOut(driver,intoUrl);

        Boolean bl =LogOutPageAction.checkLogOutTest(driver);
        if (loginInText == bl){
            Assert.assertTrue(true);
        }else {
            Assert.assertTrue(false);
        }
    }


    @AfterTest
    public void close(){
        //关闭浏览器
        driver.quit();
    }

}
